{if $data.comments}
<a name="comments"></a>
{literal}
<script language="Javascript" type="text/javascript">
    function quickreply(tree) {
    
        //hide big form
        document.getElementById('addComment').style.display = 'none';
        
        var replyForm = document.getElementById('quickAddComment');
        replyForm.style.display = '';
        var currentComment = document.getElementById(tree);
        
        var replyToField = document.getElementById('quickReplyID');
        replyToField.value = tree;
        
        currentComment.parentNode.insertBefore(replyForm, currentComment.nextSibling);
        document.getElementById('qcom').focus();
        return false;
    }
    
    function goTo(link){
        window.location.href = link;
    }
</script>
{/literal}

<h2>{#entComments#} {if $data.intime < ($smarty.const.NOW - 60*60*24*$smarty.const.COMMENT_DAYS)}{#disabled#}{/if}</h2>
<div class="comments">

    {if $data.intime > ($smarty.const.NOW - 60*60*24*$smarty.const.COMMENT_DAYS)}
        <form id="quickAddComment" method="post" action="{$SELF}addcomment/" style="display: none;" name="quickAddComment">
		    <table cellspacing="1" cellpadding="1" width="100%">
		        {dynamic}
    				{if !$smarty.session.admin}
				<tr>
				    <td colspan="4">
				        <table cellspacing="1" cellpadding="2">
				            <tr>
				                <td><nobr>{#name#}:</nobr></td>
                                <td><input type="text" name="sender" maxlength="20" style="width: 100px;" class="myInput" value="{$smarty.cookies.sender}" /></td>
                            </tr>
                            <tr>
                                <td><nobr>{#mail#}*:</nobr></td>
                                <td><input type="text" name="mail" maxlength="40" style="width: 100px;" class="myInput" value="{$smarty.cookies.senderMail}" /></td>
				            </tr>
				        </table>
				    </td>
				    
				</tr>
				    {/if}
				{/dynamic}

				<tr><td colspan="4"><textarea style="border: 1px solid #aaa; width: 100%; height: 130px;" name="comment" id="qcom">{dynamic}{$smarty.cookies.tPost}{/dynamic}</textarea></td></tr>

				{dynamic}
    				{if $smarty.const.ANTISPAM and !$smarty.session.admin}
    				    <tr><td colspan="2" align="right">{get_spam_challenge}</td><td colspan="2"><input type=text name="antispam" maxlength="6" class="myInput" style="width: 80px; {if $smarty.session.error}background:#f00; color:#fff;{/if}" value="" /></td></tr>
    				{/if}
				{/dynamic}

				<tr><td colspan="4" align="center">
				    <input type="submit" name="send" id="send" value="{#send#}" class="button" onClick="document.quickAddComment.send.disabled = true; this.value='{#pleaseWait#}'; document.getElementById('quickAddComment').submit();" />
				</td></tr>
			</table>
			
			
			<input type="hidden" name="replyto" value="" id="quickReplyID" />
		</form>
    {/if}
    
	{foreach from=$comments item=comment name=myComments}
	    
        {math equation="x * y" x=$comment.level y=30 assign="indent"}
        {if $indent > $smarty.const.COMMENT_TREE_DEPTH * 30}
            {assign var="indent" value="210"}
        {/if}
        
        {if !$comment.deleted}
        <hr class="hide" />
	    
        <!-- COMMENT START -->
        <div class="comment {if $comment.admin}reply{/if}" id="com{$comment.commentid}" name="com{$comment.commentid}" style="margin-left: {$indent}px;">            
            <div class="commentTitle">
                <div class="commentNumber"><a href="{$SELF}#comment-{$comment.commentid}" name="comment-{$comment.commentid}">{$smarty.foreach.myComments.iteration}.</a></div>
                
                <div class="gravatar">
                    {gravatar email=$comment.senderMail size=40 default="`$TEMPLATE_ROOT`images/guest.jpg"}
                </div>
                
                {if $comment.admin}
                    Alexey Kulikov &mdash; <a href="http://elance.at" target="_blank" title="elance">elance.at</a><br />
                {else}
                    {if $comment.senderURL}
                        {$comment.senderName} &mdash; <a href="{$comment.senderURL}" target="_blank">{$comment.senderURL|replace:'http://':''}</a><br />
                    {else}
                        {$comment.senderName}<br />
                    {/if}
                {/if}
                
                <span class="date">{$comment.intime|date_format:'%d.%m.%Y // %H:%M'}</span>                                        
            </div>
                
            <div style="clear: both;">
                {$comment.content}
            </div>
            
            {if $smarty.session.admin}
            <p class="datetime">
                {if (($data.intime > ($smarty.const.NOW - 60*60*24*$smarty.const.COMMENT_DAYS)) and ($comment.level < $smarty.const.COMMENT_TREE_DEPTH) and ($smarty.const.COMMENT_TREE)) or $smarty.session.admin}
                    <a href="{$SELF}" onclick='quickreply("{$comment.commentid}"); return false;' >{#reply#}</a> 
                {/if}

                {* this is weird, as I have to blend admin options our of sight *}
                {* this is the only feasible way to do so -- comment them out   *}
                {* in case non-admin follows the link it yields a 404           *}
                {dynamic}
                    {if !$smarty.session.admin}
                    <!--
                    {/if}
                {/dynamic}
                        : <a href="{$SELF}dropcomment/{$comment.sortorder}/" onClick="return confirmLink(this,'{#youSure#}');">{#delete#}</a>
                {dynamic}
                    {if !$smarty.session.admin}
                    -->
                    {/if}
                {/dynamic}                                    
            </p>
            {/if}

            <div id="{$comment.commentid}"></div>
        </div>
        <!-- COMMENT END -->
        {/if}
	{/foreach}
	
	<hr class="hide" />
	
    <form id="addComment" name="addComment" method="post" action="{$SELF}addcomment/" name="edit">
        <h3>Add a Comment</h3>
        
        <label>{#name#}:</label>
        <input type=text name="sender" maxlength="100" class="myInput" value="{dynamic}{$smarty.cookies.sender}{/dynamic}" />
        
        <label>{#mail#}:</label>
        <input type=text name="mail" maxlength="100" class="myInput" value="{dynamic}{$smarty.cookies.senderMail}{/dynamic}" />
        
        <label>URL:</label>
        <input type="text" name="url" class="myInput" value="{dynamic}{$smarty.cookies.senderURL}{/dynamic}" />
        
        <!-- antispam check -->
        <input type="text" name="commentCheck" class="myInput" value="" style="display: none;" />
        
        <label>Comment: <span class="cnote">[ Basic HTML is allowed (a href, strong, em, blockquote). ]</span></label>
        <textarea name="comment" id="mainComment">{dynamic}{$smarty.cookies.tPost}{/dynamic}</textarea>
        <div class="help"><strong>NOTE:</strong> I'd rather not moderate, but off-topic, blatantly inflammatory, or otherwise inappropriate or vapid comments may be removed. Repeat offenders will be banned from commenting. Let's add value. Thank you.</div>
        
        <input type="submit" name="send" id="send" value="{#send#}" class="button" onClick="document.addComment.send.disabled=true; this.value='{#pleaseWait#}'; document.getElementById('addComment').submit();" />
        <input type="hidden" name="replyto" value="" id="replyto" />
    </form>
</div>
{/if}